package com.ljh.extensions.rabbit.listener;

import com.ljh.extensions.rabbit.constants.Constants;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @author: Themberfue
 * @date: 2025/5/2 9:51
 * @description:
 */
@Component
public class DlListener {
//    @RabbitListener(queues = Constants.NORMAL_QUEUE)
//    public void processNormal(Message message, Channel channel) throws Exception {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        System.out.printf("[%s]收到消息：%s，deliveryTag：%d\n",
//                Constants.NORMAL_QUEUE, new String(message.getBody(), "UTF-8"), deliveryTag);
//        try {
//            int num = 3 / 0;
//            channel.basicAck(deliveryTag, false);
//        } catch (Exception e) {
//            channel.basicNack(deliveryTag, false, false);
//        }
//    }

    @RabbitListener(queues = Constants.DL_QUEUE)
    public void processDl(Message message) throws Exception {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.printf("%s：[%s]收到消息：%s，deliveryTag：%d\n",
                new Date(), Constants.DL_QUEUE, new String(message.getBody(), "UTF-8"), deliveryTag);
    }
}
